#region Using Statements
using System;
using System.Threading;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using GameStateManagement;
#endregion

namespace GameStateManagementSample
{
    class Explosion
    {
        public bool active;
        private bool firstFrame;
        private Vector2 position;
        private Texture2D texture;
        private int frameCount = 7;
        private int frame;
        public Explosion()
        {
        }

        public void setTexture(Texture2D texture)
        {
            this.texture = texture; 
        }

        public void Activate(Vector2 position, GameTime gameTime)
        {
            active = true;
            this.position = position;
            frame = 0;
            firstFrame = true;
        }

        public void Draw(GameTime gameTime, SpriteBatch spriteBatch)
        {
            if (active)
            {
                float time = (float)gameTime.TotalGameTime.TotalSeconds;
                int frameWidth = texture.Width / frameCount;
                Vector2 spritePosition = position - (new Vector2(frameWidth / 2, texture.Height / 2));
                if (firstFrame)
                {
                    frame++;
                }
                else if ((int)time % 2 == 1)
                {
                    frame++;
                }
                spriteBatch.Draw(texture, spritePosition, new Rectangle(frame * frameWidth, 0, frameWidth, texture.Height), Color.White);
                if (frame >= 6)
                {
                    active = false ;
                }
            }
        }
    }
}
